package com.controller;





import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.pojo.User;
import com.service.UserService;

@Controller
@RequestMapping("")

public class UserController {
	
	@Autowired
	UserService userService;

	@RequestMapping("listUser")
	@ResponseBody
	
	public Object listUser(){
	
		ModelAndView mav = new ModelAndView("listUser");
		List<User> cs= userService.list();
		mav.addObject("cs", cs);
	
		return cs;
	}
	
	@RequestMapping("editUser")
	public ModelAndView editUser(User s){
		ModelAndView mav = new ModelAndView("editUser");
		mav.addObject("s", s);
		return mav;
	}
	
	@RequestMapping("updateUser")
	public ModelAndView updateUser(User s){
		userService.update(s);
		ModelAndView mav = new ModelAndView("redirect:/listUser");
		return mav;
	}
	
	
	@RequestMapping("deleteUser")
	public ModelAndView deleteUser(User s){
		userService.delete(s);
		ModelAndView mav = new ModelAndView("redirect:/listUser");
		return mav;
	}
	
	@RequestMapping("addUser")
	@ResponseBody
	public 	String addUser(User s){
		System.out.println(s.getPassword());
		userService.add(s);
		return "ok";
	}	
}

